package com.Questions.doublePointer;


/**
 * 删除链表的倒数第N个结点
 */
public class leetcode19 {

    public ListNode removeNthFromEnd(ListNode head, int n) {
        if(head.next==null){
            return null;
        }
        ListNode fast=head;
        ListNode low=head;
        for(int i=0;i<n;++i){
            fast=fast.next;
        }
        if(fast==null){
            return head.next;

        }
        while (fast.next!=null){
            fast=fast.next;
            low=low.next;
        }
        // 接下来删除low的下一个结点即可
        low.next=low.next.next;
        return head;
    }
}
